import cv2
import numpy as np

img = cv2.imread('img/dotinj.jpg')
# img = cv2.imread('img/1.jpg')
# img = cv2.imread('img/tophat.jpg')

# kernel = np.ones((3, 3), np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
print(kernel)
# 腐蚀操作
# dst = cv2.erode(img, kernel, iterations=1)
# 开运算
# dst = cv2.morphologyEx(img, cv2.MORPH_ERODE, kernel)
# 闭运算
# dst = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)

# 梯度运算
# dst = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
# 礼帽运算
# dst = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)

# 黑帽运算
dst = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)

cv2.imshow('dst', dst)
cv2.imshow('img', img)
cv2.waitKey(0)